<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 18-7-29
 * Time: 上午9:39
 */

namespace common\models\db;

/**
 * Class Action
 * @package common\models\db
 *
 * @property Yii2App $yii2App
 * @property User $createdBy
 * @property RoleAction[] $roleActions
 * @property Role[] $roles
 */
class Action extends \common\models\db\tables\Action
{
    /**
     * @return \yii\db\ActiveQuery
     */
    public function getYii2App()
    {
        return $this->hasOne(Yii2App::className(), ['id' => 'yii2_app_id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getCreatedBy()
    {
        return $this->hasOne(User::className(), ['id' => 'created_by']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getRoleActions()
    {
        return $this->hasMany(RoleAction::className(), ['action_id' => 'id']);
    }

    /**
     * @return \yii\db\ActiveQuery
     */
    public function getRoles()
    {
        return $this->hasMany(Role::className(), ['id' => 'role_id'])->viaTable('{{%role_action}}', ['action_id' => 'id']);
    }
}